import Vue from 'vue'
import App from './App'
import store from './store'
import api from './utils/api.js'


//阿拉丁统计
// import './utils/ald-stat'

Vue.prototype.$store = store;
Vue.prototype.$api = api;
Vue.prototype.$imgUrl = 'https://lightplanet.tuanhaoke.cn/';
Vue.prototype.queryToken = function(sHref) {
	var obj = {}
	var args = sHref.split('?')
	if (args[0] == sHref){
		return obj
	}
	var arr = args[1].split('&')
	for (var i = 0; i < arr.length; i++) {
		var arg = arr[i].split('=')
		obj[arg[0]] = arg[1]
	}
	console.log(obj, 'obj')
	return obj
}
Vue.config.productionTip = false
uni.getSystemInfo({
	success: (resu) => {
		let platForm = false
		// #ifdef MP-WEIXIN
			platForm = "MP-WEIXIN"
		// #endif
		// 注意！这里的$isIos字段，既是ios端又是微信小程序端
		if(resu.system.indexOf("iOS")==0&&platForm=="MP-WEIXIN"){
			Vue.prototype.$isIos=true
		}
		console.log('getSystemInfo===========mian', resu)
		console.log(Vue.prototype.$isIos)
	},
	fail: (res) => {
		console.log('失败==========mian', res)
	}
})
//判断是否是H5
//#ifdef H5
// import VConsole from 'vconsole'
// let vConsole = new VConsole()
// Vue.use(vConsole)
import wx from '@/common/wx-js-sdk.js';
Vue.prototype.$isH5=true
// 分享活动
Vue.prototype.share=function(title,desc,imgUrl,link=location.href) {
	let that = this
	// 进行签名的时候  Android 不用使用之前的链接， ios 需要
	let signLink = /(Android)/i.test(navigator.userAgent) ? location.href : window.entryUrl;
	console.log('signLink', signLink)
	this.$api.get_share_params({
		token: this.token,
		url: signLink
	}).then(res => {
		console.log('执行了888', this.openid)
		if (res.status) {
			console.log('分享活动参数--------', JSON.parse(res.data))
			let data = JSON.parse(res.data)
			wx.config(data)
			wx.checkJsApi({
				jsApiList: [
					'updateTimelineShareData',
					'updateAppMessageShareData',
					'onMenuShareAppMessage',
					'onMenuShareTimeline'
				],
				success: function(res) {
					console.log('接口检测成功', res);
				},
				error: function(err) {
					console.log('接口检测失败', err);
				}
			});
			//分享功能
			wx.ready(function() {
					var shareData = {
						title: title, // 分享标题
						desc: desc, // 分享描述
						link: link,
						imgUrl: imgUrl,
						success: function(res2) {
							console.log('分享设置成功', res2)
						}
					};
					console.log('shareDate', shareData)
					wx.updateAppMessageShareData(shareData);
					wx.updateTimelineShareData(shareData);
				})
			wx.error(function(res) {
				console.log('wx.config error 11111111111111', res.errMsg);
			});
		} else {
			uni.showToast({
				title: res.msg,
				icon: 'none',
				duration: 2000
			})
		}
	}).catch(err => {
		uni.showToast({
			title: '分享接口catch到错误' + err,
			icon: 'none',
			duration: 2000
		})
		console.log('分享活动之前拿到的参数', err)
	})
}
//#endif

//#ifdef MP-WEIXIN
Vue.prototype.$isH5=false
//#endif
Vue.prototype.preImg=function(url){
	uni.previewImage({
		urls: [url],
		current: 0  
	})
},
Vue.prototype.gotoPage=function(url) {
	 uni.navigateTo({
	 url:url})
}

App.mpType = 'app'

const app = new Vue({
    ...App,
	store,
})
app.$mount()
